package com.stockz.scanner.screen;

import java.util.List;

import com.stockz.core.model.Bar;
import com.stockz.core.util.ListUtil;
import com.stockz.core.util.BarUtil.BarValueType;
import com.stockz.scanner.screen.configuration.SellingClimaxInUpTrendScreenConfiguration;
import com.stockz.ui.swing.charting.display.indicator.Stochastics;
import com.stockz.ui.swing.charting.util.MathUtil;

public class SellingClimaxInUpTrendScreen implements Screen<SellingClimaxInUpTrendScreenConfiguration> {

	private final SellingClimaxInUpTrendScreenConfiguration configuration
		= new SellingClimaxInUpTrendScreenConfiguration();
	
	@Override
	public SellingClimaxInUpTrendScreenConfiguration getConfiguration() {
		return configuration;
	}

	@Override
	public int getMandatorySpan() {
		return configuration.getStochasticsLongSpan();
	}

	@Override
	public boolean isMatch(List<Bar> barList) {
		double[] closes = ListUtil.convert(barList, BarValueType.CLOSE);
		if(Stochastics.value(closes, configuration.getStochasticsLongSpan()) > configuration.getStochasticsLongLowerLimit()){
			if(Stochastics.value(closes, configuration.getStochasticsShortSpan()) < configuration.getStochasticsShortUpperLimit()){
				double avg = MathUtil.avg(barList, BarValueType.VOLUME, 0, configuration.getVolumeAverageSpan());
				if(barList.get(0).getVolume() > avg*configuration.getVolumeMulitple()){
					return true;
				}
			}
		}
		return false;
	}

}
